﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Protal.Models;
using FluentValidation;
using Microhard.Protal.Resource;

namespace Microhard.Protal.Validators
{
    public class ServiceModelValidator : AbstractValidator<ServiceModel>
    {
        public ServiceModelValidator()
        {
            RuleSet("Insert", () =>
            {
                RuleFor(u => u.Cellphone).NotEmpty().WithMessage(Msg.NeedCellphone).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);
                RuleFor(u => u.Cellphone).Length(1, 50).WithMessage(Msg.MaxCellphone).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);
                RuleFor(u => u.ServiceContent).NotEmpty().WithMessage(Msg.NeedServiceContent).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);
                RuleFor(u => u.ServiceContent).Length(1, 250).WithMessage(Msg.MaxServiceContent).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);
            });

            RuleSet("Update", () =>
            {
                RuleFor(u => u.Cellphone).NotEmpty().WithMessage(Msg.NeedCellphone);
                RuleFor(u => u.Cellphone).Length(1, 50).WithMessage(Msg.MaxCellphone);
                RuleFor(u => u.ServiceContent).NotEmpty().WithMessage(Msg.NeedServiceContent);
                RuleFor(u => u.ServiceContent).Length(1, 250).WithMessage(Msg.MaxServiceContent);
            });
        }
    }
}
